﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Ccit.Utils;
using System.Text;
using System.Collections.Generic;
using Newtonsoft.Json;
using Ccit.OA.MsSystemDoc;

namespace Ccit.OA.SystemDoc
{
    public partial class SystemDoc_search_query : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {

                hidFolderId.Value = (null != Request.QueryString["folderId"]) ? Request.QueryString["folderId"].ToString() : "0";
                hidClassType.Value = (null != Request.QueryString["classType"]) ? Request.QueryString["classType"].ToString() : "";
                
            }
            pageinit();
        }

        private void pageinit()
        {

            string sWhere, sFolderId, sClassType, sShare;
            sFolderId = hidFolderId.Value.Trim(); ;
            sClassType = hidClassType.Value.Trim();
            SystemDocBLL Bll = new SystemDocBLL();
            string strAddrXML = Bll.GetCodeRuleMes(hidClassType.Value);
            XElement XeAddr = XElement.Parse(strAddrXML);
            var eAddrArray = from eAddr in XeAddr.Elements("ADDR") select eAddr;


            ddFolder.ClearSelection();
            foreach (var eAddr in eAddrArray)
            {
                #region 循环一级栏目
                ListItem List = new ListItem();

                sClassType = eAddr.Element("CodeID").Value; 
                List.Text = eAddr.Element("CodeNAME").Value;
                List.Value = "0" + "_06" + "_" + sClassType;
                ddFolder.Items.Add(List);
                #endregion
                #region 二级栏目及其子节点
                if (sFolderId != "0")
                {
                    sWhere = " and DOC_B2_90 = '" + sClassType + "' ";
                }
                else
                {
                    sWhere = " and DOC_B2_40 IN(" + sFolderId + ") and DOC_B2_90 = '" + sClassType + "' ";
                }
                List<MsSecondClass> msList = Bll.GetMsSecondItem(sWhere);
                if (msList.Count != 0)
                {
                    for (int i = 0; i < msList.Count; i++)
                    {

                        sShare = Bll.GetShare(msList[i].Sysdocid);
                        List = new ListItem();
                        List.Text = HttpUtility.HtmlDecode("&nbsp;&nbsp;") + msList[i].Systypename;
                        List.Value = msList[i].Sysdocid + "_" + sShare + "_" + sClassType;

                        ddFolder.Items.Add(List);
                        DDBind(msList[i].Sysdocid, sClassType, "&nbsp;&nbsp;", sShare);
                    }
                }
                msList = null;
                #endregion

            }

            for (int i = 0; i < 5; i++)
            {
                this.rbDatetime.Items[i].Attributes.Add("onclick", "rbDate()");
                this.rbsize.Items[i].Attributes.Add("onclick", "rbSize()");
            }
            txtsizezd.Attributes.Add("onKeyDown", "CliNumber('txtsizezd')");
            btsearch.Attributes.Add("onclick", "return  doSearch()");

            Bll = null;
        }

        public void DDBind(string Superiorid, string classType, string sbEmpty, string sParaShare)
        {
            string sWhere, sFolderId, sShare;
            sFolderId = hidFolderId.Value.Trim();
            sbEmpty += "&nbsp;&nbsp;";
            sWhere = " and DOC_B2_40 IN(" + Superiorid + ") and DOC_B2_90 = '" + classType + "' ";
            SystemDocBLL Bll = new SystemDocBLL();
            List<MsSecondClass> msList = Bll.GetMsSecondItem(sWhere);

            if (msList.Count != 0)
            {

                for (int i = 0; i < msList.Count; i++)
                {
                    if (sParaShare == "01" || sParaShare == "00")
                    {
                        sShare = sParaShare;
                    }
                    else
                    {
                        sShare = Bll.GetShare(msList[i].Sysdocid);
                    }

                    ListItem List = new ListItem();
                    List.Text = HttpUtility.HtmlDecode(sbEmpty) + msList[i].Systypename;
                    List.Value = msList[i].Sysdocid + "_" + sShare + "_" + classType;

                    ddFolder.Items.Add(List);
                    DDBind(msList[i].Sysdocid, classType, sbEmpty, sShare);
                }
            }
            Bll = null;
            msList = null;
        }
    }
}
